local halberdSkill = fk.CreateSkill{
  name = "#lvshi__halberd_skill",
  attached_equip = "lvshi__halberd",
}

halberdSkill:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(halberdSkill.name) and data.card.trueName == "slash" and #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = data:getExtraTargets(),
      min_num = 1,
      max_num = 2,
      skill_name = halberdSkill.name,
      cancelable = true,
      prompt = "#lvshi__halberd-ask",
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/halberd")
    room:setEmotion(player, "./packages/standard_cards/image/anim/halberd")
    local tos = event:getCostData(self).tos
    data.extra_data = data.extra_data or {}
    data.extra_data.saHalberd = true
    room:sendLog{
      type = "#HalberdTargets",
      from = player.id,
      to = table.map(tos, Util.IdMapper),
      arg = "halberd",
      card = Card:getIdList(data.card),
    }
    for _, p in ipairs(tos) do
      data:addTarget(p)
    end
  end
})

halberdSkill:addEffect(fk.CardEffectCancelledOut, {
  name = "#lvshi__halberd_delay",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and (player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data.extra_data or {}).saHalberd
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    local use = e.data
    if #use.tos > 0 then
      room:sendLog{
        type = "#HalberdNullified",
        from = target.id,
        arg = "lvshi__halberd",
        arg2 = data.card:toLogString(),
      }
      use.nullifiedTargets = use.tos
    end
  end,
})

return halberdSkill